package com.learning.security.api;

import com.learning.security.api.dto.AdminOAuth2AccessTokenCheckRespDTO;
import com.learning.security.dal.dataobject.AdminOAuth2AccessTokenDO;
import com.learning.security.service.AdminOAuth2TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminOAuth2TokenApiImpl implements AdminOAuth2TokenApi {
    @Autowired
    private AdminOAuth2TokenService adminOAuth2TokenService;

    @Override
    public AdminOAuth2AccessTokenCheckRespDTO checkAccessToken(String accessToken) {
        AdminOAuth2AccessTokenDO accessTokenDO = adminOAuth2TokenService.checkAccessToken(accessToken);

        return new AdminOAuth2AccessTokenCheckRespDTO().setUserId(accessTokenDO.getUserId())
                .setUserType(accessTokenDO.getUserType())
                .setUserInfo(accessTokenDO.getUserInfo())
                .setTenantId(accessTokenDO.getTenantId())
                .setScopes(accessTokenDO.getScopes());
    }
}
